package com.bank2.controller;

import com.bank2.domain.User;
import com.bank2.mapper.User2Mapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class User2Controller {
    @Autowired
    private User2Mapper user2Mapper;
    @GetMapping("/add")
    public String add(String name,int account){
        user2Mapper.insert(new User(name, account));
        return "添加成功";//直接返回了，没有判断
    }
    @GetMapping("/byName")
    public String add(String name){
        if(StringUtils.isEmpty(name)){
            throw new RuntimeException("查询name不得为空");
        }
        User user = user2Mapper.selectOne(new LambdaQueryWrapper<User>().eq(User::getName, name));
        if(user==null)
            return "查询无果";
        return user.getName()+":"+user.getAmount();
    }


}
